home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-10-07 | 5.9 KB | 248 lines | [TEXT/MACA] |
- \ © J. Langowski / MacTutor, 1986
- \ written in NEON v. 2.0
-
- DECIMAL
- -35 CONSTANT nsvErr ( no such volume error )
- -43 CONSTANT fnfErr ( file not found error )
-
- HEX
- 3F6 CONSTANT FSFCBLen \ >0 if HFS is being used
- -1 CONSTANT MFS \ -1 if MFS is running
- ( this global variable is given for your information. )
- ( It is automatically checked by the NEON 2.0 word hfs? )
-
- 10 CONSTANT Dir/File \ bit 4 determines whether it is
- \ a file or directory
-
- DECIMAL
-
- \ Routine selectors for HFS traps
- 1 CONSTANT OpenWD
- 2 CONSTANT CloseWD
- 5 CONSTANT CatMove
- 6 CONSTANT DirCreate
- 7 CONSTANT GetWDInfo
- 8 CONSTANT GetFCBInfo
- 9 CONSTANT GetCatInfo
- 10 CONSTANT SetCatInfo
- 11 CONSTANT SetVolInfo
- 16 CONSTANT LockRng
- 17 CONSTANT UnlockRng
-
- \ some more constants
- 80 CONSTANT FileParamSize
- 106 CONSTANT CatParamSize
-
- \ offsets into parameter block
- 12 CONSTANT ioCompletion ( completion routine [long word] )
- 16 CONSTANT ioResult ( result code returned here [word] )
- 18 CONSTANT ioNamePtr \ holds pointer to file name string or
- \ pathname string [long word]
- 22 CONSTANT ioVRefNum
- 24 CONSTANT FioFRefNum ( path reference number [word] )
- 26 CONSTANT FioFVersNum ( usually zero [byte] )
- 28 CONSTANT FioFDirIndex ( index [word] )
- 30 CONSTANT FioFlAttrib ( file attributes byte [byte] )
- 31 CONSTANT FioFlVersNum ( version number [byte] )
- 32 CONSTANT FioFlFndrInfo
- 48 CONSTANT FioDirID
- 48 CONSTANT FioFlNum
-
-
- 0 value Index
- 0 value VolRefNum
- 0 value DirID
-
- : ?dup dup if dup then ;
-
- \ the HFS dispatcher...
- create hfsD
- popD0
- popA0
- $ A060 w,
- pushD0
- next,
-
- : $openWD { name -- VRefNum / errcode 0 }
- 0 fFcb ioCompletion + !
- name +base fFcb ioNamePtr + !
- 0 fFcb FioFDirIndex + w!
- fFcb +base OpenWD hfsD extend
- ?dup if 0 else fFcb ioVRefNum + w@ then
- ;
-
- : getixHFSfile { indx \ ResCode -- errorResCode }
- \ setup parameter block:
- VolRefNum fFcb ioVRefNum + W! \ specify the volume
- DirID fFcb FioDirID + ! \ pass directory id
- pad +base fFcb ioNamePtr + ! \ expect file name here
- indx fFcb FioFDirIndex + W! \ pass current index
- hfs? IF fFcb +base GetCatInfo hfsD extend -> ResCode
- ELSE fFcb fcall PBGetFInfo extend -> ResCode
- THEN
- ResCode \ pass ResCode on stack
- ;
-
- : NextFile 1 ++> index index getixHFSFile ;
-
- 0 value level
-
- : indent cr level 4 * spaces ; ( for pretty printing )
-
- : DIR { vol \ resCode -- }
- 0 -> Index ( initialize index )
- vol -> VolRefNum ( choose volume in internal drive )
- 2 -> DirID ( specify root directory, only significant in HFS )
-
- BEGIN
- NextFile -> resCode
- ResCode 0=
- IF
- indent
- fFcb FioFlAttrib + C@ ( get the attributes byte )
- Dir/File AND ( file or directory ? )
- IF indent
- 33 tface ." Directory -> " pad count type
- 0 tface
- 1 ++> level
- index volrefnum ( push on stack )
- pad $openwd DIR ( recursive call to DIR )
- -> volrefnum -> index ( pop off stack )
- -1 ++> level
- indent
- ELSE pad count type
- THEN
- THEN
- ResCode
- UNTIL ( error found )
-
- ResCode ( which error ? )
- CASE
- fnfErr OF
- level ?dup
- IF cr 1- 4 * spaces
- 33 tface ." End of directory" 0 tface
- ELSE cr 33 tface ." End of contents listing"
- 0 tface quit
- THEN
- ENDOF
- nsvErr OF cr ." There is no disk in drive number " vol . ENDOF
- cr ." Error #" ResCode .
- ENDCASE
- ;
-
-
- String gpattern
- String linBuf
- String target
-
- 0 value #lines \ total lines searched
-
- \ SEARCHFILE - This routine searches a file for the presence of
- \ gpattern, outputting all lines that contain the string.
- \ It is contained in the 'grep' source file on the NEON 2.0 disk.
- \ Please insert the appropriate source code here....
- \ ...
- \ ...
- \ ...
-
- : grepInit
- 0 -> #lines
- indent ." Searching for: " print: gPattern CR
- uc: gPattern 2drop
- new: linBuf
- ;
-
- : grepDIR { vol addr len \ resCode gcurs -- }
- new: loadFile new: gpattern new: target
- addr len str255 -base count put: gPattern
- curs -> gcurs -curs \ Preserve cursor status
- grepInit
- 0 -> Index \ initialize index
- vol -> VolRefNum \ choose volume in internal drive
- 2 -> DirID \ specify root directory , immaterial for MFS
-
- BEGIN ?pause
- NextFile -> resCode
- ResCode 0=
- IF
- indent
- fFcb FioFlAttrib + C@ \ get the attributes byte
- Dir/File AND \ file or directory?
- IF indent
- 33 tface ." Directory -> " pad count type
- 0 tface
- 1 ++> level
- index volrefnum \ push on stack
- pad $openwd addr len grepDIR
- \ recursive call to grepDIR
- -> volrefnum -> index \ pop off stack
- -1 ++> level
- indent
- ELSE pad count type
- pad count name: topFile
- volrefnum setVref: topfile
- openReadOnly: topFile ?error 132
- GetFileInfo: topFile drop
- GetType: topFile txType =
- IF searchfile THEN
- close: topFile drop
- THEN
- THEN
- ResCode \ go until error found
- UNTIL
-
- ResCode
- CASE
- fnfErr OF
- level ?dup
- IF cr 1- 4 * spaces
- 33 tface ." End of directory" 0 tface
- ELSE cr 33 tface ." End of contents listing"
- 0 tface gcurs -> curs remove: loadfile quit
- THEN
- ENDOF
- nsvErr OF
- cr ." There is no disk in drive number " vol . ENDOF
- cr ." Error #" ResCode .
- ENDCASE
- remove: loadfile
- ;
-
- 0 value drive
-
- : grepone
- new: loadFile
- txtype 1 stdget: topfile
- IF
- " Enter search string:" doInDlg
- IF new: gpattern new: target
- str255 -base count put: gPattern
- cls grepinit
- openreadonly: topfile ?error 132
- searchfile
- remove: loadFile
- THEN
- THEN
- ;
-
- : grepd 0 -> level
- drive " Enter search string:"
- doInDlg if cls grepdir else drop then
- ;
-
- 1 menu filemenu
- 3 menu editmenu
- 7 menu grepmenu
-
- : drive1 1 -> drive 5 uncheck: grepmenu 4 check: grepmenu ;
- : drive2 2 -> drive 4 uncheck: grepmenu 5 check: grepmenu ;
- : pron +print 7 uncheck: grepmenu 6 check: grepmenu ;
- : proff -print 6 uncheck: grepmenu 7 check: grepmenu ;
-
- : init
- " grepmenu.txt" getmtxt
- drive1 proff
- ;
-
-